﻿namespace Sidvall.LogManager.UI
{
	public partial class SystemContext
	{
		#region Public Members

		public global::Sidvall.LogManager.UI.Entities.Model.DataPortal DataPortal { get; set; }
		public global::Sidvall.LogManager.UI.Entities.Model.EntityCache EntityCache { get; set; }
		public global::Sidvall.LogManager.UI.Entities.Model.EntityFacade EntityFacade { get; set; }

		#endregion
		#region Factory Members

		static partial void OnCreateSystemContext(SystemContext item);
		private static readonly object _Mutex = new object();
		private static volatile SystemContext _Current;
		public static SystemContext Current
		{
			get
			{
				if (_Current == null)
				{
					lock (_Mutex)
					{
						if (_Current == null)
						{
							var item = new SystemContext()
							{
								DataPortal = new global::Sidvall.LogManager.UI.Entities.Model.DataPortal(
									new global::Sidvall.LogManager.Model.Local.DataPortalFactory(),
									new global::Sidvall.LogManager.Model.Remote.DataPortalFactory()
								),
								EntityCache = new global::Sidvall.LogManager.UI.Entities.Model.EntityCache(),
								EntityFacade = new global::Sidvall.LogManager.UI.Entities.Model.EntityFacade(),
							};
							OnCreateSystemContext(item);
							_Current = item;
						}
					}
				}
				return _Current;
			}
			set
			{
				lock (_Mutex)
				{
					_Current = value;
				}
			}
		}

		#endregion
		#region Constructors

		public SystemContext()
		{
		}

		#endregion
	}
}